package com.spc.car.web.controller.std;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.core.framework.web.domain.AjaxResult;
import com.spc.car.data.domain.std.po.EnterpriseQualificationQueryPO;
import com.spc.car.data.entity.std.StdEnterpriseQualification;
import com.spc.car.data.service.std.StdEnterpriseQualificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;


@Validated
@RequestMapping("/standard")
@Api(tags = "标准")
@RestController
public class StdEnterpriseQualificationController {

    @Autowired
    private StdEnterpriseQualificationService enterpriseQualificationService;

    @ApiOperation(value = "查询机构资质信息", notes = "查询机构资质信息")
    @PostMapping("/listEnterpriseQualification")
    public AjaxResult listEnterpriseQualification(@RequestBody(required = false) EnterpriseQualificationQueryPO queryPO) {

        QueryWrapper<StdEnterpriseQualification> condition = new QueryWrapper<StdEnterpriseQualification>();
        Page page = new Page(0, 10);
        if (Objects.nonNull(queryPO)) {
            condition.like(StringUtils.isNotBlank(queryPO.getName()),
                        "name", queryPO.getName());
            page = new Page(ObjectUtils.defaultIfNull(queryPO.getPage(), 0),
                    ObjectUtils.defaultIfNull(queryPO.getPageSize(), 10));
        }

        return AjaxResult.success("查询机构资质信息成功",
                enterpriseQualificationService.page(page, condition));
    }
}
